package ticketmachine.logic;

import java.util.Collection;

import ticketmachine.dataObjects.DAOFactory;
import ticketmachine.dataObjects.IStationDAO;
import ticketmachine.dataObjects.ITicketDescriptionDAO;
import ticketmachine.logic.Ticket.TicketDetails;


public class TicketMachineFacade {
	
	private ITicketDescriptionDAO ticketDescriptionDAO;
	private IStationDAO stationDAO;
	private TicketMachine tm;
	
	private static TicketMachineFacade tmf;
	
		
	public TicketMachineFacade() {
		ticketDescriptionDAO=DAOFactory.getInstance().getTicketDescriptionDAO();
		stationDAO = DAOFactory.getInstance().getStationDAO();
		tm = new TicketMachine();
		tm.Inicialiate();
		
		
	}
    
	public static TicketMachineFacade getInstance(){
		if (tmf==null){
			tmf=new TicketMachineFacade();
		}
		return tmf;
	}
	
	
	public Collection<TicketDescription> getAllTicketTypes(){
		return ticketDescriptionDAO.getAllTicketDescriptions();
	}
	
	public Collection<Station> getAllStations(){
		return stationDAO.listStations();
	}
	
	public void startNewTransaction(int transactionType){
		tm.startNewTransAction(transactionType);
	}
	
	public void setTicketType(int type){
		tm.setTicketType(type);
	}

    public void setDestination(int stationId) {
        tm.setTicketDestination(stationId);
    }

    public float calculateTicketPrice() {
          return tm.getCurrentTransaction().calculateTicketPrice();
    }
    
    public TicketDetails getTicketDetails(){
    	return tm.getCurrentTransaction().getTicket().getTicketDetails();
    }

    public void applyTicketPromotion(int promotionId) {
            tm.applyTicketPromotion(promotionId);
     }

    public void setFamilySize(int familySize) {

        tm.setFamilySize(familySize);
        tm.getCurrentTransaction().calculateTicketPrice();

    }

    public void reloadTicket() {
        tm.getCurrentTransaction().calculateTicketPrice();
        tm.applyTicketPromotion(tm.getCurrentTransaction().ticket.getPromotion().id);
    }
    
    public float makeNewCashPayment(float amountDue, float amountIntroduced){
    	return tm.getCurrentTransaction().makeNewCashPayment(amountDue,amountIntroduced);    	
    }

    public float makeNewCreditPayment(String cardNumber, String expiry, Float amount ) {

        return tm.getCurrentTransaction().makeNewCreditPayment(cardNumber, expiry, amount);
        
    }
    public float makeNewDebitPayment(String pin, String cardNbr, float amount) {

        return tm.getCurrentTransaction().makeNewDebitPayment(pin, cardNbr, amount);
    }

    public float makeNewECashPayment(String pin, float amount) {

        return tm.getCurrentTransaction().makeECashPayment(pin, amount);

    }


}
